package com.taru.houseapp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

/**
 * 配置swagger接口文档
 */
@Configuration
@EnableSwagger2
public class SpringFoxConfig {

    //配置swagger的Docket容器
    @Bean
    public Docket customDocket(Environment environment){
        //获取文件
        Profiles profiles=Profiles.of("dev","test");
        //监听当前环境
        boolean flag=environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(flag)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.taru.houseapp.controller"))
                .build();
    }
    //配置信息
    public ApiInfo apiInfo(){
        Contact contact=new Contact("陈博凯","","1677970713@qq.com");
        return new ApiInfo(
                "租房APP项目API接口文档",
                "简单实现租房业务",
                "1.0",
                "",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }

}
